package cn.bugstack.test;

import cn.bugstack.infrastructure.persistent.redis.IRedisService;
import cn.bugstack.infrastructure.persistent.redis.RedissonService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.redisson.api.RMap;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApiTest {

    @Resource
    private IRedisService redisService;
    @Test
    public void test() {
//        存放数据
        RMap<Object, Object> map = redisService.getMap("strategy_id_100001");
        map.put(1,101);
        map.put(2,101);
        map.put(3,101);
        map.put(4,102);
        map.put(5,102);
        map.put(6,102);
        map.put(7,103);
        map.put(8,103);
        map.put(9,104);
        map.put(10,105);
        log.info("测试结果：{}",redisService.getFromMap("strategy_id_100001",5).toString());

    }
    public void test_(){
        int[] nums = {100,4,200,1,3,2};
        Map<Integer,Integer> map = new HashMap<>();
        for(int i = 0;i<nums.length;i++){
            map.put(nums[i],i);
        }
        int result = 0;
        for(int i = 0;i<nums.length;i++){
            int n = 0;
            int temp = nums[i];
            while(map.containsKey(temp)){
                temp++;
                n++;
            }
            if(n>result){
                result = n;
            }
        }
    }

}
